from engineio import json
from flask import request

from app.libs.error import APIException

class Select(APIException):
    code=201
    msg = 'ok'
    error_code = 0
    content=[{}]

    def get_body(self, environ=None):
        body = dict(
            msg=self.msg,
            error_code=self.error_code,
            request=request.method + '' + self.get_url_no_param(),
            content=self.content
        )
        text = json.dumps(body)
        return text

class ApiTestFail(APIException):
    code=200
    msg = '接口断言失败，检测参数'
    error_code = 0
    content=[{}]

    def get_body(self, environ=None):
        body = dict(
            msg=self.msg,
            error_code=self.error_code,
            request=request.method + '' + self.get_url_no_param(),
            content=self.content
        )
        text = json.dumps(body)
        return text
class ApiTestSuccess(APIException):
    code=200
    msg = '接口断言成功'
    error_code = 0
    content=[{}]

    def get_body(self, environ=None):
        body = dict(
            msg=self.msg,
            error_code=self.error_code,
            request=request.method + '' + self.get_url_no_param(),
            content=self.content
        )
        text = json.dumps(body)
        return text
class Success(APIException):
    code = 200
    msg = '请求成功'
    error_code = 0
    content = [{}]

    def get_body(self, environ=None):
        body = dict(
            msg=self.msg,
            error_code=self.error_code,
            request=request.method + '' + self.get_url_no_param(),
            content=self.content
        )
        text = json.dumps(body)
        return text


class DeleteSuccess(Success):
    code = 202
    error_code = 1

class ServerError(APIException):
    code = 500
    msg = '未知错误'
    error_code = 999


class ClientTypeError(APIException):
    # 400请求参数错误，401未授权，403禁止访问，404未找到资源
    # 200访问成功，201创建成功，204删除成功
    code = 400
    msg = 'client is invalid'
    error_code = 1006


class ParameterException(APIException):
    code = 400
    msg = 'invalid parameter'
    error_code = 1000


class NotFount(APIException):
    code = 404
    msg = 'the resource are not_fount 0__0 '
    error_code = 1001


class AuthFailed(APIException):
    code = 401
    msg = 'the resource are not_fount 0__0 '
    error_code = 1005

class Forbidden(APIException):
    code = 403
    msg = 'forbidden,not in scope '
    error_code = 1004